<%--
  Created by IntelliJ IDEA.
  User: 陈帅玺
  Date: 2019-01-04
  Time: 14:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set value="${pageContext.request.contextPath}" var="path"></c:set>
<!DOCTYPE html>
<html>
<head>
    <title>分配服务</title>
    <link rel="stylesheet" href="/assets/css/loader-style.css">
    <link rel="stylesheet" href="/assets/css/bootstrap.css">
    <link rel="stylesheet" href="/layui/css/layui.css">
    <script src="/js/jquery-3.3.1.js"></script>
    <script src="/layui/layui.js"></script>
    <script src="/js/config.js"></script>
    <link rel="shortcut icon" href="/assets/ico/minus.png">
    <style>
        .box-pad {
            padding: 1%
        }
        #distri {
            display: none;
            padding: 30px 50px 0 50px;
        }
    </style>
</head>
<body>
<div id="distri">
<form class="layui-form" id="distriForm">
    <input type="hidden" name="id" id="sid" value="{{id}}">
    <input type="hidden" name="stat"  value="1">
    <div class="layui-form-item">
        <label class="layui-form-label">分配给：</label>
        <div class="layui-inline">
            <select id="roles" name="assigner">
                <option value="-1">请选择</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">分配时间：</label>
        <div class="layui-input-inline">
            <input type="text" name="assignerTime" id="distriTime" class="layui-input" readonly>
        </div>
    </div>
    <input type="hidden" name="userid" id="aa">
</form>
</div>

<div class="box-pad">
    <h1>服务分配</h1>
    <hr>
    <form class="layui-form">
        <%--<input type="text" name="userid" id="ida" value="${sessionScope.crmUser.id}">--%>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">客户名：</label>
                <div class="layui-inline">
                    <input type="text" id="clientele" class="layui-input" autocomplete="off">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">服务类型：</label>
                <div class="layui-inline">
                    <select id="serviceType" name="typeid" class="layui-select">
                        <option value="-1">请选择</option>
                        <c:forEach items="${crmDictionaries}" var="cd">
                            <option value="${cd.id}">${cd.name}</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
            <button type="button" class="layui-btn" style="margin-bottom: 10px" onclick="searchData()">查询</button>
        </div>
    </form>
    <table class="layui-table" lay-data="{url:'/Service/getassign',page:true, id:'userTable',toolbar:'#toolbarDemo',defaultToolbar: ['filter', 'print', 'exports'],even: true}" lay-filter="userTable">
        <thead>
        <tr>
            <th lay-data="{field:'id', width:80, sort: true}">ID</th>
            <th lay-data="{field:'clientele', width:180}">用户名</th>
            <th lay-data="{templet:'#typeid'}">服务类型</th>
            <th lay-data="{field:'outline'}">概要</th>
            <th lay-data="{field:'request'}">服务请求</th>
            <th lay-data="{toolbar:'#barDemo'}">操作</th>
        </tr>
        </thead>
    </table>

    <script>
        $.get("${path}/Service/search",function (data) {
            $.each(data,function () {
                var opt = $("<option></option>").appendTo("#roles");
                opt.text(this.username).val(this.id);
            });
        })
        function searchData(){
            layui.table.reload("userTable",{
                page:{
                    curr : 1
                },
                where:{
                    "clientele":$("#clientele").val(),
                    "typeid" : $("#serviceType").val()
                }
            });
        }


        //  layui渲染
        var table;
        layui.use(['table','form'], function () {
            table = layui.table;
            var form = layui.form;
            table.on('tool(userTable)',function (obj) {
                var e = obj.event;
                var data=obj.data;
                $("#sid").val(data.id)
                switch (e){
                    case "distri":
                        layer.open({
                            type: 1,
                            title: "分配人员",
                            skin: "layui-layer-molv",
                            anim: 0,
                            offset:"260px;",
                            area: "550px",
                            content: $("#distri"),
                            btn: ['确定','取消'],
                            yes : function (index) {
                                var role=$("#roles").val();
                                if(role==-1){
                                    layer.msg("仔细填写...",{icon:5,time:1200,anim:6},function () {});
                                    return false;
                                }
                                var aaa=($("#roles").val());
                                $("#aa").val(aaa);
                                var str = $("#distriForm").serialize();
                                console.log(str);
                                $.post("${path}/Service/addfenpei",str,function (){
                                    layer.close(index);
                                    table.reload('userTable');
                                });

                            }
                        })
                        break;
                    case "del":
                        layer.open({
                            time:0,
                            title:'友情提示',
                            offset:"280px",
                            content:'确定要删除此行数据吗？',
                            shade:[0.3,'#000'],
                            btn:['确定','取消'],
                            yes:function () {
                                $.post("${path}/Service/deleteService",{id:data.id},function () {
                                    layer.msg('删除成功...',{time:1200,offset: '260px'});
                                    table.reload('userTable');
                                })
                            }
                        })
                        break;
                }
            })
            //  获取时间
            function getNow(s) {
                return s < 10 ? '0' + s : s;
            }

            function dates() {
                var now = new Date();
                //格式化日，如果小于9，前面补0
                var day = ("0" + now.getDate()).slice(-2);
                //格式化月，如果小于9，前面补0
                var month = ("0" + (now.getMonth() + 1)).slice(-2);
                // var h = now.getHours();
                // var minute = now.getMinutes();
                // var s = now.getSeconds();
                //拼装完整日期格式
                var today = now.getFullYear() + "-" + (month) + "-" + (day);
                // var today = now.getFullYear() + "-" + (month) + "-" + (day) + " " + getNow(h) + ":" + getNow(minute) + ":" + getNow(s);
                return today;
            }
            $("#distriTime").val(dates());
        })
    </script>
    <script type="text/html" id="typeid">
        {{d.dictionariesid.name}}
    </script>
    <!--  分配、删除  -->
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-xs " lay-event="distri" title="分配"><span class="layui-icon layui-icon-release"></span></a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" title="删除"><span class="layui-icon layui-icon-delete"></span></a>
    </script>
</div>
</body>
</html>
